home *** CD-ROM | disk | FTP | other *** search
/ Windows Undocumented File Formats / Windows Undocumented File Formats.img / CHAP4 / WINHELP.H < prev   
Encoding:
C/C++ Source or Header  |  1997-07-17  |  12.7 KB  |  324 lines

  1. /**********************************************************************
  2.  *
  3.  * PROGRAM: WINHELP.H
  4.  *
  5.  * PURPOSE: Sample header file for an .HLP file
  6.  *
  7.  * Copyright 1997, Mike Wallace and Pete Davis
  8.  *
  9.  * Chapter 4, Windows Help File Format, from Undocumented Windows
  10.  * File Formats, published by R&D Books, an imprint of Miller Freeman, Inc.
  11.  *
  12.  **********************************************************************/
  13.  
  14. /* Force byte aligned packing of data structures */
  15. #pragma pack(1)
  16.  
  17.  
  18. /*
  19.    The following are defined as based on the Windows 3.1
  20.    Programmer's Reference.
  21. */
  22. #ifndef _INC_WINDOWS
  23. typedef unsigned char   BYTE;
  24. typedef unsigned short  WORD;
  25. typedef unsigned long   DWORD;
  26.  
  27. typedef struct tagRGBTRIPLE
  28. {
  29.     BYTE    rgbBlue;
  30.     BYTE    rgbGreen;
  31.     BYTE    rgbRed;
  32. } RGBTRIPLE;
  33.  
  34. typedef DWORD COLORREF;
  35.  
  36. #define RGB(r,g,b) ((COLORREF) \
  37.             (((BYTE)(r)|((WORD)(g)<<8))|(((DWORD)(BYTE)(b))<<16)))
  38.  
  39. #endif
  40.  
  41. /* Define the size of a Topic Block 4k - sizeof(TOPICLINK) */
  42. #define TopicBlockSize   4096L
  43.  
  44.  
  45. /***********************************************************
  46.    WinHelp Common Structures
  47. ************************************************************/
  48.  
  49. /* Help file Header record */
  50. typedef struct tagHELPHEADER {
  51.     DWORD   MagicNumber;      /* 0x00035F3F                */
  52.     long    HFSLoc;           /* Pointer to WHIFS header   */
  53.     long    Negative1;
  54.     long    FileSize;         /* Size of entire .HLP File  */
  55. } HELPHEADER;
  56.  
  57. #define HF_MAGIC  0x00035F3F
  58.  
  59. /* File Header for WHIFS files */
  60. typedef struct tagHFSFILEHEADER {
  61.     long    FilePlusHeader;  /* File size including this header */
  62.     long    FileSize;        /* File size not including header  */
  63.     char    FileType;      /*                                 */
  64. } HFSFILEHEADER;
  65.  
  66. /* File types used by HFS               */
  67. /* FT_NORMAL is a regular file                */
  68. /* FT_HFS is the HFS directory file         */
  69. /* FT_UNK Found in MSDNCD4.MVB |TTLBTREE file   */
  70.  
  71. #define FT_NORMAL 0x00
  72. #define FT_HFS    0x04
  73.  
  74.  
  75. /***********************************************************
  76.    B-Tree related structures
  77. ************************************************************/
  78.  
  79. /* Keyword & TTL BTREE Headers - Slightly different than HFS B-tree Header.
  80.    Both HFS and Keyword B-Trees use same leaf and index node headers.    */
  81.  
  82. typedef struct tagBTREEHEADER {
  83.   WORD  Signature;        /* 0x293B                               */
  84.   char  Unknown1;         /* 0x02 always                          */
  85.   char  FileTypeFlag;     /* Same as FILEHEADER FileTypeFlag field*/
  86.   short PageSize;         /* Size of tree pages                   */
  87.   char  SortOrder[16];    /* Used for internationalization        */
  88.   short FirstLeaf;      /* Probably First Leaf page!!!          */
  89.   short NSplits;        /* # of page splits Btree has suffered  */
  90.   short RootPage;       /* page #of root page                   */
  91.   short Reserved2;
  92.   short TotalPages;     /* total # of 2Kb pages in Btree        */
  93.   short nLevels;        /* # of levels in this Btree            */
  94.   DWORD TotalBtreeEntries;
  95. } BTREEHEADER;
  96.  
  97. /* Modified B-Tree Leaf Header */
  98. typedef struct tagBTREELEAFHEADER {
  99.     WORD    Signature;      /* Signature word            */
  100.     short   NEntries;       /* Number of entries         */
  101.     short   PreviousPage;   /* Index of Previous Page    */
  102.     short   NextPage;       /* Index of Next Page        */
  103. } BTREELEAFHEADER;
  104.  
  105. /* Modified B-Tree Index node header */
  106. typedef struct tagBTREEINDEXHEADER {
  107.     WORD    Signature;      /* Signature byte            */
  108.     short   NEntries;       /* Number of entries in node */
  109. } BTREEINDEXHEADER;
  110.  
  111. /***********************************************************
  112.    |Phrases header
  113. ************************************************************/
  114.  
  115. /* Phrases header. In uncompressed, last field doesn't exist */
  116. typedef struct tagPHRASEHEADER    {
  117.     short   NumPhrases;     /* Number of phrases in table                     */
  118.     WORD    OneHundred;     /* 0x0100                                         */
  119.     long    PhrasesSize;    /* Amount of space uncompressed phrases requires. */
  120. } PHRASEHEADER;
  121.  
  122.  
  123. /***********************************************************
  124.    |FONT File structures
  125. ************************************************************/
  126.  
  127. /* Header for |FONT file */
  128. typedef struct tagFONTHEADER {
  129.     WORD    NumFonts;           /* Number of fonts in Font List */
  130.     WORD    NumDescriptors;     /* Number of font descriptors   */
  131.     WORD    DefDescriptor;      /* Default font descriptor      */
  132.     WORD    DescriptorsOffset;  /* Offset to descriptor list    */
  133. } FONTHEADER;
  134.  
  135. typedef struct tagFONTDESCRIPTOR {
  136.     BYTE    Attributes;         /* Font Attributes See values below */
  137.     BYTE    HalfPoints;         /* PointSize * 2                    */
  138.     BYTE    FontFamily;         /* Font Family. See values below    */
  139.     BYTE    FontName;           /* Number of font in Font List      */
  140.     BYTE    Unknown;            /* Unknown                          */
  141.     RGBTRIPLE SRRGB;            /* RGB values of foreground         */
  142.     RGBTRIPLE NSRRGB;           /* background RGB Values (?? Not sure */
  143. } FONTDESCRIPTOR;
  144.  
  145. /* Font Attributes */
  146. #define FONT_NORM    0x00       /* Normal         */
  147. #define FONT_BOLD    0x01       /* Bold           */
  148. #define FONT_ITAL    0x02       /* Italics        */
  149. #define FONT_UNDR    0x04       /* Underline      */
  150. #define FONT_STRK    0x08       /* Strike Through */
  151. #define FONT_DBUN    0x10       /* Dbl Underline  */
  152. #define FONT_SMCP    0x20       /* Small Caps     */
  153.  
  154. /* Font Families */
  155. #define FAM_MODERN   0x01
  156. #define FAM_ROMAN    0x02
  157. #define FAM_SWISS    0x03
  158. #define FAM_TECH     0x03
  159. #define FAM_NIL      0x03
  160. #define FAM_SCRIPT   0x04
  161. #define FAM_DECOR    0x05
  162.  
  163.  
  164. /***********************************************************
  165.    |SYSTEM file structures
  166. ************************************************************/
  167.  
  168. /* Header for |SYSTEM file */
  169. typedef struct tagSYSTEMHEADER {
  170.     BYTE    Magic;     /* 0x6C                  */
  171.     BYTE    Version;   /* Version #             */
  172.     BYTE    Revision;  /* Revision code         */
  173.     BYTE    Always0;   /* Unknown               */
  174.     WORD    Always1;   /* Always 0x0001         */
  175.     DWORD   GenDate;   /* Date/Time that the help file was generated    */
  176.     WORD    Flags;     /* Values seen: 0x0000 0x0004, 0x0008, 0x000A    */
  177. } SYSTEMHEADER;
  178.  
  179. /* Magic number of SYSTEM record */
  180. #define SYS_MAGIC     0x6C
  181.  
  182. /* Flags for |SYSTEM header Flags field below */
  183. #define NO_COMPRESSION          0x0000
  184. #define COMPRESSION_HIGH        0x0004
  185.  
  186. /* Help Compiler 3.1 System record. Multiple records possible */
  187. typedef struct tagSYSTEMREC {
  188.     WORD    RecordType;   /* Type of Data in record      */
  189.     WORD    DataSize;     /* Size of RData               */
  190.     char    *RData;       /* Raw data (Icon, title, etc) */
  191. } SYSTEMREC;
  192.  
  193. /* Types for SYSTEMREC RecordType below */  
  194. #define HPJ_TITLE       0x0001      /* Title from .HPJ file            */
  195. #define HPJ_COPYRIGHT   0x0002      /* Copyright notice from .HPJ file */
  196. #define HPJ_CONTENTS    0x0003      /* Contents=??? from .HPJ          */
  197. #define MACRO_DATA      0x0004      /* SData = 4 nulls if no macros    */
  198. #define ICON_DATA       0x0005
  199. #define HPJ_SECWINDOWS  0x0006      /* Secondary window info in .HPJ   */
  200. #define HPJ_CITATION    0x0008      /* CITATION= under [OPTIONS]       */
  201.  
  202.  
  203. /* Secondary Window Record following type 0x0006 System Record */
  204.  
  205. typedef struct tagSECWINDOW {
  206.     WORD    Flags;          /* Flags (See Below)        */
  207.     BYTE    Type[10];       /* Type of window           */
  208.     BYTE    Name[9];        /* Window name              */
  209.     BYTE    Caption[51];    /* Caption for window       */
  210.     WORD    X;              /* X coordinate to start at */
  211.     WORD    Y;              /* Y coordinate to start at */
  212.     WORD    Width;          /* Width to create for      */
  213.     WORD    Height;         /* Height to create for     */
  214.     WORD    Maximize;       /* Maximize flag            */
  215.     BYTE    Rgb[3];
  216.     BYTE    Unknown1;
  217.     BYTE    RgbNsr[3];      /* RGB for non scrollable region */
  218.     BYTE    Unknown2;
  219. } SECWINDOW;
  220.  
  221. /** Values for Flags **/
  222.  
  223. #define WSYSFLAG_TYPE       0x0001  /* Type is valid        */
  224. #define WSYSFLAG_NAME       0x0002  /* Name is valid        */
  225. #define WSYSFLAG_CAPTION    0x0004  /* Ccaption is valid    */
  226. #define WSYSFLAG_X          0x0008  /* X    is valid        */
  227. #define WSYSFLAG_Y          0x0010  /* Y    is valid        */
  228. #define WSYSFLAG_WIDTH      0x0020  /* Width    is valid    */
  229. #define WSYSFLAG_HEIGHT     0x0040  /* Height   is valid    */
  230. #define WSYSFLAG_MAXIMIZE   0x0080  /* Maximize is valid    */
  231. #define WSYSFLAG_RGB        0x0100  /* Rgb  is valid        */
  232. #define WSYSFLAG_RGBNSR     0x0200  /* RgbNsr   is valid    */
  233. #define WSYSFLAG_TOP        0x0400  /* On top was set in HPJ file */
  234.  
  235.  
  236. /***********************************************************
  237.    Keyword file structures
  238. ************************************************************/
  239.  
  240. /* Keyword Map Record */
  241. typedef struct tagKWMAPREC {
  242.     long    FirstRec;       /* Index number of first keyword on leaf page    */
  243.     WORD    PageNum;        /* Page number that keywords are associated with */
  244. } KWMAPREC;
  245.  
  246. /* Record for the |KWBTREE file */
  247. typedef struct tagKWBTREEREC {
  248.     char     Keyword[80];     /* Variable Length Keyword      */
  249.     short    Count;           /* Count of Keywords occurances */
  250.     long     KWDataOffset;    /* Offset into |KWDATA file     */
  251. } KWBTREEREC;
  252.  
  253.  
  254. /***********************************************************
  255.    |TOPIC file structures
  256. ************************************************************/
  257.  
  258. /* |TOPIC Block header - Header for a block of topic data. If
  259.    uncompressed, there's only one of these at the beginning of the
  260.    file. If the help file is compressed, then these occur in 4k
  261.    increments. (e.g. 0x0000, 0x1000, 0x2000, 0x3000, 0x4000, etc. ) */
  262.  
  263. typedef long  TOPICOFFSET;
  264.  
  265. typedef struct tagTOPICBLOCKHEADER {
  266.     long    LastTopicLink;   /* Offset of last topic link in previous block   */
  267.     long    TopicData;       /* Offset of topic data start                    */
  268.     long    LastTopicHeader; /* Offset of last topic header in previous block */
  269. } TOPICBLOCKHEADER;
  270.  
  271. /* Linked list record for |TOPIC file */
  272. typedef struct tagPARAGRAPH {
  273.     long     BlockSize;   /* Size of this link + Data         */
  274.     long     DataLen2;    /* Length of LinkData2              */
  275.     long     PrevBlock;   /* Relative to first byte of |TOPIC */
  276.     long     NextBlock;   /* Relative to first byte of |TOPIC */
  277.     long     DataLen1;    /* Len(LinkData1 + 11(hdr size))    */
  278.     BYTE     RecordType;  /* See below                        */
  279.     BYTE     *LinkData1;  /* Data associated with this link   */
  280.     BYTE     *LinkData2;  /* Second set of data               */
  281. } PARAGRAPH;
  282.  
  283. /* Known record types for topic link */
  284. #define TL_TOPICHDR    0x02  /* Topic header information */
  285. #define TL_DISPLAY     0x20  /* Displayable information  */
  286. #define TL_TABLE       0x23  /* WinHelp Table            */
  287.  
  288. /* Topic header. Starts inside LinkData of a type 0x02 record */
  289. typedef struct tagTOPICHEADER {
  290.     long          BlockSize; /* Size of topic, including internal topic links  */
  291.     TOPICOFFSET   BrowseBck; /* Topic offset for prev topic in Browse sequence */
  292.     TOPICOFFSET   BrowseFor; /* Topic offset for next topic in Browse sequence */
  293.     DWORD         TopicNum;  /* Topic Number(?)                                */
  294.     long          NonScroll; /* Start of Non-Scroll Region                     */
  295.     long          Scroll;    /* Start of Scrolling Region of text.             */
  296.     TOPICOFFSET   NextTopic; /* Start of next Type 0x02 record                 */
  297. } TOPICHEADER;
  298.  
  299. /***********************************************************
  300.    Structures for other system files
  301. ************************************************************/
  302.  
  303. /* Header for |TOMAP file */
  304. typedef struct tagTOMAPHEADER {
  305.     long    IndexTopic;   /* Index topic for help file */
  306.     long    Reserved[15];
  307.     short   ToMapLen;     /* Number of topic pointers  */
  308.     long    *TopicPtr;    /* Pointer to all the topics */
  309. } TOMAPHEADER;
  310.  
  311. /* Record from |CTXOMAP file. Created from the [MAP] section of .HPJ file */
  312. typedef struct tagCTXOMAPREC {
  313.     long     MapID;
  314.     long     TopicOffset;
  315. } CTXOMAPREC;
  316.  
  317.  
  318. /* Record from |CONTEXT file */
  319. typedef struct tagCONTEXTREC {
  320.     long     HashValue;       /* Hash value of a phrase     */
  321.     long     TopicOffset;     /* Topic offset of the phrase */
  322. } CONTEXTREC;
  323.  
  324.